package com.example.foobar.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.foobar.business.service.DaRemarkService;
import com.example.foobar.dao.service.DaRemarkDaoService;
import com.example.foobar.entity.DaRemark;
import com.example.foobar.entity.DaRetentionRates;
import com.example.foobar.param.DaRemarkPageParam;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class DaRemarkServiceImpl implements DaRemarkService {

    @Autowired
    private DaRemarkDaoService daRemarkDaoService;

    @Override
    public boolean saveDaRemark(DaRemark daRemark) {
        return daRemarkDaoService.saveDaRemark(daRemark);
    }

    @Override
    public boolean updateDaRemark(int uniacid, Date date, String remark) {
        LambdaQueryWrapper<DaRemark> wrapper = new LambdaQueryWrapper<>(DaRemark.class).eq(DaRemark::getUniacid, uniacid)
                .eq(DaRemark::getBaseDate, date);
        int i = daRemarkDaoService.selectCount(wrapper);
        int flag = -1;
        if(i > 0){
            daRemarkDaoService.delete(wrapper);
        }
        DaRemark daRemark = new DaRemark();
        daRemark.setBaseDate(date);
        daRemark.setRemark(remark);
        daRemark.setUniacid(uniacid);
        daRemark.setUpdateTime(new Date());
        flag = daRemarkDaoService.insert(daRemark);

        return flag > 0 ? true:false;
    }

    public boolean deleteDaRemark(Long id) {
        return daRemarkDaoService.deleteDaRemark(id);
    }

    @Override
    public DaRemark getById(Long id) {
        return daRemarkDaoService.getById(id);
    }

    @Override
    public void insert(DaRemark daRemark) {

    }
}
